import UIKit

print("----0个参数------")
func hello1() {
  print("hello")
}

hello1()

let hello1Closure = { () in
  print("hello1")
}

hello1Closure()

print("----1个参数------")
func hello2(name: String) {
  print("hello2 \(name)")
}

hello2(name: "张三")

let hello2Closure = { (name: String) in
  print("hello2Closure: \(name)")
}

hello2Closure("张三")

print("----2个参数------")
func sum(a: Int, b: Int) -> Int {
  a + b
}

print(sum(a: 10, b: 2))

// 1.复制函数定义
// 2.复制函数体
// 3.变量接收
let sumClosure = { (a: Int, b: Int) -> Int in
  a + b
}

print(sumClosure(10, 2))

print("----无参数返回值------")

func hello4() -> String {
  "你好椭圆"
}

print(hello4())
let hello4Closure = { () -> String in
  "你好椭圆."
}

print(hello4Closure())

print("----函数做参数------")

func sayHi(action: () -> Void) {
  action()
  print("张三")
}

let sayHiClosure = { (action: () -> Void) in
  action()
  print("张三.")
}

let action = { () in
  print("你好")
}

sayHi(action: action)
